using System.Collections.Generic;
using UnityEngine.Recorder.Input;

namespace UnityEngine.Recorder
{
	[ExecuteInEditMode]
	public class ImageRecorderSettings : RecorderSettings
	{
		public PNGRecordeOutputFormat m_OutputFormat = PNGRecordeOutputFormat.JPEG;

		private ImageRecorderSettings()
		{
			m_BaseFileName.pattern = "image_<0000>.<ext>";
		}

		public override List<RecorderInputSetting> GetDefaultInputSettings()
		{
			List<RecorderInputSetting> list = new List<RecorderInputSetting>();
			list.Add(NewInputSettingsObj<CBRenderTextureInputSettings>("Pixels"));
			return list;
		}

		public override bool ValidityCheck(List<string> errors)
		{
			bool result = base.ValidityCheck(errors);
			if (string.IsNullOrEmpty(m_DestinationPath.GetFullPath()))
			{
				result = false;
				errors.Add("Missing destination path.");
			}
			if (string.IsNullOrEmpty(m_BaseFileName.pattern))
			{
				result = false;
				errors.Add("missing file name");
			}
			return result;
		}

		public override bool SelfAdjustSettings()
		{
			if (base.inputsSettings.Count == 0)
			{
				return false;
			}
			bool result = false;
			if (base.inputsSettings[0] is RenderTextureSamplerSettings)
			{
				RenderTextureSamplerSettings renderTextureSamplerSettings = (RenderTextureSamplerSettings)base.inputsSettings[0];
				ColorSpace colorSpace = (m_OutputFormat == PNGRecordeOutputFormat.EXR) ? ColorSpace.Linear : ColorSpace.Gamma;
				if (renderTextureSamplerSettings.m_ColorSpace != colorSpace)
				{
					renderTextureSamplerSettings.m_ColorSpace = colorSpace;
					result = true;
				}
			}
			if (base.inputsSettings[0] is ImageInputSettings)
			{
				ImageInputSettings imageInputSettings = (ImageInputSettings)base.inputsSettings[0];
				if (imageInputSettings.maxSupportedSize != EImageDimension.x4320p_8K)
				{
					imageInputSettings.maxSupportedSize = EImageDimension.x4320p_8K;
					result = true;
				}
			}
			return result;
		}

		public override List<InputGroupFilter> GetInputGroups()
		{
			List<InputGroupFilter> list = new List<InputGroupFilter>();
			list.Add(new InputGroupFilter
			{
				title = "Pixels",
				typesFilter = new List<InputFilter>
				{
					new TInputFilter<ScreenCaptureInputSettings>("Screen"),
					new TInputFilter<CBRenderTextureInputSettings>("Camera(s)"),
					new TInputFilter<Camera360InputSettings>("360 View (feature preview)"),
					new TInputFilter<RenderTextureSamplerSettings>("Sampling"),
					new TInputFilter<RenderTextureInputSettings>("Render Texture")
				}
			});
			return list;
		}
	}
}
